<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统用户管理</title> <#include "/WEB-INF/content/module-edit.html">
<script type="text/javascript">
var sysStatus = [
		<#list map["status"] as sysStatus>
		<#if sysStatus_index!=0>
		,
		</#if>
          {"id":"${sysStatus.ecode}","text":"${sysStatus.ename}"}
		</#list>
];
var sysGroup = [
		<#list map["group"] as sysGroup>
		<#if sysGroup_index!=0>
		,
		</#if>
          {"id":"${sysGroup.code}","text":"${sysGroup.groupName}"}
		</#list>
];
	$(function() {
		$('#account').validatebox({
			required : true,
			validType : [
					"code",
					'remote["${request.contextPath}/sys/user/validate/account", "account", "${object.account!}"]' ]
		});
		$("#status").combobox({
			valueField : 'id',
			textField : 'text',
			data:sysStatus
		});	
		$("#groupCode").combobox({
			valueField : 'id',
			textField : 'text',
			data:sysGroup
		});	
		  $("#user_org").combotree({ 
			 url:'${request.contextPath}/sys/user/org',
			 editable:false
			 }); 	
		  $("#user_org").combotree("setValue","${object.user_org!}");
	});
	function subButtonFormatter(value, rowData, rowIndex){
		var html = "";
			if(value=="${_id}"){
				 html = "<a href=\"#\" onclick=\"javascript:permission('"
					+ rowData.code
					+ "',false);\" style=\"text-decoration:none;border: 1px solid #A8B8D1;background:#eee;\">取消</a>";
			}else{
				 html = "<a href=\"#\" onclick=\"javascript:permission('"
					+ rowData.code
					+ "',true);\" style=\"text-decoration:none;border: 1px solid #A8B8D1;background:#eee;\">授权</a>";
			}
		return html;
	}
	function permission(module,permission){
		$.post( "role",{_permission:permission,_module:module}, function(data) {
				var msg = "保存失败";
				if (data.state) {
					msg = "保存成功";
					top.showMsg(msg);
					$("#sub").datagrid("reload");
				} else {
					top.showMsg(msg);
				}
			}
		);
	}
	function defaultRole(role){
		$.post( "roleDefault",{_module:role}, function(data) {
				var msg = "保存失败";
				if (data.state) {
					msg = "保存成功";
					top.showMsg(msg);
					$("#sub").datagrid("reload");
				} else {
					top.showMsg(msg);
				}
			}
		);
	}
	function priFormatter(value, rowData, rowIndex){
		if(value==0){
			  return "是";
		}else{
			if(rowData.auth_user=="${_id}"){
				var html = "否";
				<@auth code="sys:user:*:roleDefault">
					html+= "&nbsp;&nbsp;&nbsp;<a href='#' onclick=\"javascript:defaultRole('"+rowData.code+"')\" style=\"text-decoration:none;border: 1px solid #A8B8D1;background:#eee;\">设为默认</a>";
				</@auth>
				return html;
			}
			else
				return "否";
		}
	}
</script>
</head>
<body class="easyui-layout">
	<div region="north"
		style="background-color: #eee; padding: 5px; overflow: hidden;"
		border="false">
		<#if object.account?exists&&object.account!=""> <@auth
		code="sys:user:update"><a href="#" class="easyui-linkbutton"
			plain="true" iconCls="icon-add" style="border: 1px solid #ccc"
			onclick="javascript:save()">保存</a></@auth> <#else> <@auth
		code="sys:user:create"><a href="#" class="easyui-linkbutton"
			plain="true" iconCls="icon-add" style="border: 1px solid #ccc"
			onclick="javascript:save()">保存</a></@auth> </#if> <a href="#"
			class="easyui-linkbutton" plain="true" iconCls="icon-edit"
			style="border: 1px solid #ccc" onclick="javascript:cancel()">关闭</a>
	</div>
	<div region="center">
		<div id="p" class="easyui-panel"
			style="background: #fafafa; padding: 10px" fit="true"
			toolbar="#toolbar">
			<form id="form" method="post">
				<table class="form" cellspacing="0" style="width: 100%">
					<tbody style="border: 1px solid #ccc">
						<tr style="display: none;">
							<td colspan="6"><input id="_id" value="${object.account!}"></td>
						</tr>
						<tr>
							<td class="label">账号：</td>
							<td><#if object.account?exists&&object.account!=""> <#assign
								readonly="readonly=\"readonly\""> </#if> <input id="account"
								name="account" value="${object.account!}"
								${readonly!}  />
							</td>
							<td class="validate">*</td>
							<td class="label">名称：</td>
							<td><input id="name" name="name" value="${object.name!}"
								class="easyui-validatebox" required="required" /></td>
							<td class="validate">*</td>
						</tr>
						<tr>
							<td class="label">别名：</td>
							<td><input id="alias" name="alias" value="${object.alias!}" /></td>
							<td class="validate"></td>
							<td class="label">状态：</td>
							<td><input id="status" name="status"
								value="${object.status!}" required="required" /></td>
							<td class="validate"></td>
						</tr>
						<tr>
							<td class="label">所属用户组：</td>
							<td><input id="groupCode" name="groupCode"
								value="${object.groupCode!}" /></td>
							<td class="validate">*</td>
							<td class="label">创建时间：</td>
							<td>${object.create_time!}</td>
							<td class="validate"></td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
	<@auth code="sys:user:*:sub"> <#if _id??&&_id!="">
	<div region="south"
		style="background-color: #eee; padding: 5px; overflow: hidden; height: 250px;"
		border="false">
		<table id="sub" class="easyui-datagrid" url="sub" idField="code"
			rownumbers="true" striped="true" fitColumns="true" fit="true"
			singleSelect="true">
			<thead>
				<tr>
					<th field="code" width="5">所属角色编码</th>
					<th field="name" width="10">角色名称</th>
					<th field="pri" formatter="priFormatter" width="30">默认角色</th><@auth
					code="sys:user:*:role">
					<th field="auth_user" width="10" formatter="subButtonFormatter"
						align="center">操作</th></@auth>
				</tr>
			</thead>
		</table>
	</div>
	</#if> </@auth>
</body>
</html>